package cn.wolfcode.shop.service;

import cn.wolfcode.shop.domain.PropertyValue;
import cn.wolfcode.shop.mapper.PropertyValueMapper;
import com.alibaba.dubbo.config.annotation.Service;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service@Transactional
public class PropertyValueServiceImpl implements IPropertyValueService {
    @Autowired
    private PropertyValueMapper propertyValueMapper;

    @Override
    public List<PropertyValue> selectByPId(Long propertyId) {
        return propertyValueMapper.selectByPId(propertyId);
    }

    @Override
    public void saveOrUpdate(List<PropertyValue> propertyValues) {
        for (PropertyValue propertyValue : propertyValues) {
            if (propertyValue.getId() != null) {
                propertyValueMapper.updateByPrimaryKey(propertyValue);
            } else {
                propertyValueMapper.insert(propertyValue);
            }
        }
    }

    @Override
    public void delete(Long id) {
        propertyValueMapper.deleteByPrimaryKey(id);
    }
}
